//
//  CQPlaceholderLabel.m
//  BiaoliApp
//
//  Created by qian on 2020/12/15.
//

#import "CQPlaceholderLabel.h"

@implementation CQPlaceholderLabel


- (void)setText:(NSString *)text {
    super.text = text;
    [self __updateText:NO];
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    [self __updateText:YES];
}

- (void)setEnabled:(BOOL)enabled {
    [super setEnabled:enabled];
    [self __updateTextColor];
}

- (void)setTextColor:(UIColor *)textColor {
    [super setTextColor:textColor];
    
    _normalTextColor = textColor;
    [self __updateTextColor];
}

- (void)__updateText:(BOOL)isSetPlaceholder {
    [self __updateTextOrTextColor:isSetPlaceholder];
}

- (void)__updateTextColor {
    [self __updateTextOrTextColor:NO];
}

- (void)__updateTextOrTextColor:(BOOL)isSetPlaceholder {
    NSString *currentText = self.text;
    if (isSetPlaceholder && currentText.length == 0) {
        [super setText:self.placeholder];
        [super setTextColor:self.placeholderColor];
    } else {
        if (self.enabled == NO) {
            [super setTextColor:self.disableTextColor];
        } else {
            [super setTextColor:self.normalTextColor];
        }
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
